package ccnu.agile.config.rbac;

import ccnu.agile.mapper.ProjectMemberRoleMapper;
import ccnu.agile.mapper.ResourceMapper;
import ccnu.agile.mapper.RoleMapper;
import ccnu.agile.mapper.RoleResourceMapper;
import ccnu.agile.utils.RBACUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * @Description: 系统成功启动后运行配置类
 * @Author: JreamY
 * @Date: 2021/10/30
 **/
@Component
@ConditionalOnProperty(value = "capd.config.rbac-switch", havingValue = "true")
public class RBACConfig implements ApplicationRunner {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private ResourceMapper resourceMapper;

    @Autowired
    private RoleResourceMapper roleResourceMapper;

    @Autowired
    private ProjectMemberRoleMapper projectMemberRoleMapper;

    @Override
    public void run(ApplicationArguments args) {
        RBACUtils.init(
                roleMapper.fetchAll(0),
                resourceMapper.fetchAll(0),
                roleResourceMapper.fetchAll(0),
                projectMemberRoleMapper.fetchAll(0)
        );
    }
}
